package newKe;

import java.util.Scanner;
import java.util.Stack;

public class HJ70 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long res = 0;
        int N = Integer.parseInt(in.nextLine());
        int[][] mat = new int[N][2];

        for(int i=0;i<N;i++){
            String s = in.nextLine();
            String[] arr = s.split(" ");
            mat[i][0] = Integer.parseInt(arr[0]);
            mat[i][1] = Integer.parseInt(arr[1]);
        }

        int index = 0;
        // 栈
        Stack<Integer> stack = new Stack<>();
        String s = in.nextLine();
        for (char c : s.toCharArray()) {
            if(c == '('){

            } else if (c>='A'&&c<='Z') {
                stack.push(mat[index][0]);
                stack.push(mat[index++][1]);
            } else if (c == ')') {
//                弹出两个矩阵进行计算，再入栈
                int a = stack.pop();//2 lie
                int b = stack.pop();//2 hang
                int aa = stack.pop();//1 lie
                int bb = stack.pop();//1 hang

                res+=aa*bb*a;
                stack.push(bb);
                stack.push(a);
            }
        }

        System.out.println(res);
    }
}
